package com.yoomiito.app.adapter.my

import android.net.Uri
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.model.my.MyOrderBean
import com.yoomiito.app.utils.DataUtils
import com.yoomiito.app.utils.ResUtil
import com.yoomiito.app.utils.SpannableUtils
import com.yoomiito.app.widget.CircleImageView

class MonthOrderAdapter : BaseQuickAdapter<MyOrderBean, BaseViewHolder>(R.layout.item_my_order, null) {

    override fun convert(helper: BaseViewHolder?, item: MyOrderBean?) {
        helper?.getView<TextView>(R.id.tv_name)?.text = item?.nickname
        helper?.getView<TextView>(R.id.tv_order_num)?.text = ResUtil.getString(R.string.my_order_num) + item?.order_id
        helper?.getView<TextView>(R.id.tv_money)?.text = "" + SpannableUtils.handlePrice(item?.user_income)
        val requestOptions = RequestOptions()
        requestOptions.placeholder(R.drawable.goods_default)
        if (!TextUtils.isEmpty(item?.headimgurl)) {
            helper?.getView<CircleImageView>(R.id.iv_photo)?.let {
                Glide.with(App.getApplication()).load(Uri.parse(item?.headimgurl)).apply(requestOptions).into(it)
            }
        }
        helper?.getView<ImageView>(R.id.iv_st).let {
            val i = DataUtils.ivType(item?.order_type)
            if (i == -1) it?.visibility = View.GONE else it?.setImageResource(i)
        }

        val failView = helper?.getView<View>(R.id.item_my_order_fail)
        when (item?.status) {
            1 -> {//待结算
                helper?.getView<View>(R.id.iv_status)?.visibility = View.GONE
                failView?.visibility = View.GONE

                helper?.setGone(R.id.statusTv,true)
                helper?.getView<TextView>(R.id.statusTv).let {
                    it?.text = "待结算"
                    it?.visibility = View.VISIBLE
                    it?.setTextColor(ResUtil.getColor(R.color.color_FFF7D00))
                }
            }
            2 -> {//已结算
                failView?.visibility = View.GONE
                helper?.getView<View>(R.id.iv_status)?.visibility = View.GONE

                helper?.setGone(R.id.statusTv,true)
                helper?.getView<TextView>(R.id.statusTv).let {
                    it?.text = "已结算"
                    it?.visibility = View.VISIBLE
                    it?.setTextColor(ResUtil.getColor(R.color.color_balk_999999))
                }
            }
            3 -> {//失效
                failView?.visibility = View.VISIBLE
                helper?.getView<View>(R.id.iv_status)?.visibility = View.VISIBLE
                helper?.getView<ImageView>(R.id.iv_status)?.setImageResource(R.mipmap.failure)
                helper?.setGone(R.id.statusTv,false)
            }
        }
        helper?.getView<TextView>(R.id.tv_date)?.text = item?.ctime
    }
}